using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Markup;
using Common;
using MainView.MainControls;
using SExperiment;
using SProject;

namespace MainView.View
{
	public partial class UCExperimentRunComplete : UserControl, IDisposable, IComponentConnector
	{
		private Experiment _Experiment;

		public UCExperimentRunComplete(Experiment experiment)
		{
			_Experiment = experiment;
			base.DataContext = _Experiment;
			InitializeComponent();
			ucTemperatureChartComplate.DisplayAllData();
		}

		public void Dispose()
		{
			ucTemperatureChartComplate.Dispose();
		}

		public void RefreshProjectInfo()
		{
			tabControlProjectInfo.Items.Clear();
			List<Project> list = (from s in _Experiment.Wells
				where s.Project != null
				select s.Project).Distinct().ToList();
			foreach (Project item in list)
			{
				UCExperimentProjectInfo uCExperimentProjectInfo = new UCExperimentProjectInfo();
				uCExperimentProjectInfo.DataContext = item;
				uCExperimentProjectInfo.PCRVisible = false;
				UserControl userControl = uCExperimentProjectInfo;
				if (list.Count == 1)
				{
					tabControlProjectInfo.Visibility = Visibility.Collapsed;
					gridProjectInfo.Children.Add(userControl);
					continue;
				}
				tabControlProjectInfo.Visibility = Visibility.Visible;
				TabItem tabItem = new TabItem();
				tabItem.Style = Utility.GetResource("TabItemStylesmall") as Style;
				tabItem.Header = item.BasicInfo.Name;
				tabItem.Content = userControl;
				tabControlProjectInfo.Items.Add(tabItem);
			}
			if (tabControlProjectInfo.Items.Count > 0)
			{
				tabControlProjectInfo.SelectedIndex = 0;
			}
			tabControlProjectInfo.RefreshTabItemStyle();
		}

		[DebuggerNonUserCode]
		[GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
		internal Delegate _CreateDelegate(Type delegateType, string handler)
		{
			return Delegate.CreateDelegate(delegateType, this, handler);
		}
	}
}
